<!--
 * @Description: 修改客户名称
 * 
 * @Author: XiongYaoYuan<xiongyaoyuan>
 * @Date: 2023-07-08 23:20:29
 * @FilePath: /yuxiuproweb/src/views/mes/pro/workorder/mods/add/editName.vue
-->
<template>
  <el-dialog
    :close-on-click-modal="false"
    v-dialogDrag
    title="修改客户名称"
    :visible.sync="shows"
    width="500px"
    append-to-body
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="86px">
      <el-row>
        <el-col :span="24">
          <el-form-item label="客户名称" prop="name">
            <el-input v-model="form.name" placeholder="请输入客户名称" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="shows = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { updateOrder } from "@/api/asc/order";
export default {
  props: {
    show: Boolean,
    data: {
      type: Object,
    },
  },
  data() {
    return {
      // 表单参数
      form: {
        name: "",
      },
      // 表单校验
      rules: {
        name: [{ required: true, message: "请输入客户名称", trigger: "blur" }],
      },
    };
  },
  computed: {
    shows: {
      get() {
        return this.show;
      },
      set(newValue) {
        this.$emit("update:show", newValue);
      },
    },
  },
  created() {
    if (this.data) {
      this.form = {
        name: this.data.clientName,
      };
    }
  },
  methods: {
    /** 提交按钮 */
    async submitForm() {
      try {
        await this.$refs["form"].validate();
        updateOrder({
          ...this.data,
          clientName: this.form.name,
        }).then(() => {
          this.$modal.msgSuccess("修改成功");
          this.$emit("on-change", this.form);
          this.shows = false;
        });
      } catch (e) {
        console.log(e);
      }
    },
  },
};
</script>
